package com.moji.controller.api;


import com.moji.common.Commons;
import com.moji.common.base.ApiResult;
import com.moji.common.config.OperateLog;
import com.moji.common.entity.MyPage;
import com.moji.entity.SysRole;
import com.moji.entity.dto.PrOnOffDto;
import com.moji.service.SysRoleService;
import com.moji.util.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-07-23
 */
@RestController
@RequestMapping("api/sysRole")
@Api(tags = "角色信息", value = "角色信息接口")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;


    @PostMapping("add")
    @ApiOperation("保存角色信息数据")
    @OperateLog(moduleName = "角色管理",content = "保存角色信息",operateType = Commons.OPERATE_TYPE.ADD)
    public ApiResult save(@RequestBody SysRole ccpSystemRole){
        return ApiResult.ok(sysRoleService.add(ccpSystemRole));
    }

    @PostMapping("update")
    @ApiOperation("编辑角色信息数据")
    @OperateLog(moduleName = "角色管理",content = "编辑角色信息",operateType = Commons.OPERATE_TYPE.EDIT)
    public ApiResult update(@RequestBody SysRole sysRole){
        return ApiResult.ok(sysRoleService.edit(sysRole));
    }

    @GetMapping("delete")
    @ApiOperation("删除角色信息数据")
    @OperateLog(moduleName = "角色管理",content = "删除角色信息",operateType = Commons.OPERATE_TYPE.DELETE)
    public ApiResult delete(Long id){
        return ApiResult.ok(sysRoleService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询角色信息数据")
    public ApiResult queryPage(@RequestBody SysRole sysRole){
        MyPage<SysRole> ccpSystemRoleMyPage = sysRoleService.queryPage(sysRole);
        return ApiResult.ok(ccpSystemRoleMyPage);
    }

    @GetMapping("roleSelectBox")
    @ApiOperation("查询角色下拉框数据")
    public ApiResult roleSelectBox(){
        return ApiResult.ok(sysRoleService.queryRoleSelectBox());
    }

    @PostMapping("updateRoleStatus")
    @ApiOperation("更新角色启停状态")
    public ApiResult updateRoleStatus(@RequestBody PrOnOffDto prOnOffDao){
        return ApiResult.ok(sysRoleService.updateRoleStatus(prOnOffDao));
    }

    @GetMapping("queryRoleTree")
    @ApiOperation("查询角色树形数据")
    public ApiResult queryRoleTree(){
        return ApiResult.ok(sysRoleService.queryRoleTree());
    }

    @GetMapping("queryRoleAuth")
    @ApiOperation("查询角色已有权限")
    public ApiResult queryRoleAuth(String roleCode){
        return ApiResult.ok(sysRoleService.queryRoleAuth(roleCode));
    }
}

